﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}

<form id="form1" runat="server" method="post" style="height: 100%">
   <div class="mini-splitter" style="width:100%;height:100%;">
        <div size="270" showcollapseButton="true">
            <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
                <a class="mini-button" iconcls="icon-remove" onclick="removeAll()" plain="true">清空</a>                  
                <a class="mini-button" iconcls="icon-downgrade" onclick="Send" plain="true">发放</a>
                <span class="separator"></span>
            </div>
            <div id="DivHeader0">
                <table>
                    <tr>
                        <td style="width:150px;height:28px;">提示：选择会员后按添加按钮添加到左边的列表。</td>
                    </tr>
                 </table>
                 <table>
                    <tr>
                        <td style="width:150px;height:40px;">已选择会员列表</td>
                        <td style="width:50px;height:40px;">
                            <input type="button" value="移除--" onclick="removes()" style="width:55px;font-size:9px"/> 
                        </td>
                        <td style="width:50px;height:40px;">
                            <input type="button" value="<<添加" onclick="adds()" style="width:55px;font-size:9px"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-fit">
                <div id="grid2" class="mini-datagrid" style="width:100%;height:100%;" showPager="false"
                    borderStyle="border:2;" allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true" fitColumns="false" idField="id" 
                    multiSelect="true" allowResize="true" ondrawsummarycell="onDrawSummaryCell" showSummaryRow="true" >
                    <div property="columns">
                        <div type="checkcolumn" ></div>                            
                        <div field="FPhone" name="FPhone" width="120px" headeralign="center">电话号码</div>
                        <div field="FName" name="FName" width="95px" headeralign="center">会员名称</div>
                    </div>
                </div>
            </div>
        </div>
        <div showCollapseButton="true">
                <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                    <table style="width: 100%;">
                        <tr>
                            <td style="width: 100%;">
                                <a class="mini-button" iconcls="icon-search" onclick="LoadData" plain="true">刷新</a>
                                <span class="separator"></span>
                                <a class="mini-button" iconcls="icon-goto" onclick="clearloca" plain="true">重置</a>
                                <span class="separator"></span>                                
                                <a class="mini-button" iconcls="icon-ok" onclick="AutoSend" plain="true">自动营销</a>
                                <span class="separator"></span>
                                <a class="mini-button" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                            </td>
                        </tr>
                    </table>
                </div>

                <div id="DivHeader">
                    <table>
                        <tr>
                            <td width="70px" align="right">商户名称：</td>
                            <td width="240px">
                                @Html.Partial("~/Views/Modular/LookupCorpInfo.cshtml")
                            </td>
                            <td width="70px" align="right">性别：</td>
                            <td width="150px" height ="32px">
                                    <input id="FSex" name="FSex" class="mini-combobox" style="width:125px;" showNullItem="false" 
                                        allowInput="false" align="left" value ="-1" data ="comSexType"/> 
                            </td>                
                            <td width="70px" align="right">会员分类：</td>
                            <td class="style18">
                                <input id="memberLevel" class="mini-combobox" style="width: 150px;" textfield="FName" valuefield="FItemID" shownullitem="true"/>
                            </td>
                            <td width ="70px" align="right">会员搜索：</td>
                            <td width ="160px">
                                <input id ="FNumber" name="FNumber" class="mini-textbox" style="width:160px;"/>
                            </td>
                            <td width ="80px" align="center">
                            </td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td width="70px" align="right">生日范围：</td>
                            <td width="190px">
                                @Html.Partial("~/Views/Modular/dxMonthDayRange.cshtml")
                            </td>
                            <td width="70px" align="right">
                                <div id="FBrDate" name="FBrDate" class="mini-checkbox" style="margin-right:20px" readOnly="false" value="false" text="按会员生日范围过滤">
                            </td>
                            <td width="70px" align="right">非活跃会员：</td>
                            <td width="160px">
                                <input id="FDays" name="FDays" class="mini-textbox" style="width:153px;" value="0" />天内
                            </td>
                            <td width="70px" align="right">会员标签：</td>
                            <td width="160px">
                                <div id="TagComBox" name="TagComBox" class="mini-combobox" style="width:153px;" popupWidth="300" textField="FName" valueField="FItemID"
                                     value="" multiSelect="true" showClose="true" oncloseclick="onCloseClick">
                                    <div property="columns">
                                        <div header="ID" field="FItemID"></div>
                                        <div header="标签" field="FName"></div>
                                    </div>
                                </div>
                            </td>
                            <td width="80px" align="center">
                                <a class="mini-button" iconCls="icon-search" style="width:80px;" onclick="LoadData" plain="true">查询</a>
                            </td>
                        </tr>
                    </table>
                </div>

                <div class="mini-fit">
                    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" borderstyle="border:1;" pagesize="15"
                         url="../Member/GetMemberListByPm" multiselect="true">
                        <div property="columns">
                            <div type="checkcolumn"></div>
                            <div field="FItemID" width="110" headeralign="center" visible="false">id</div>
                            <div field="FNumber" width="110" headeralign="center">会员编码</div>
                            <div field="FName" width="200" headeralign="center">会员名称</div>
                            <div field="FPhone" name="FPhone" width="100" headeralign="center" align="right">电话号码</div>
                            <div field="FClassName" name="FClassName" width="100" headeralign="center" align="right">会员分类</div>
                            <div field="FAmount" name="FAmount" width="100" headeralign="center" align="right" numberformat="#,0.00">余额</div>
                            <div field="FPoint" name="FPoint" width="100" headeralign="center">积分</div>
                            <div field="FCreateDate" name="FCreateDate" width="100" headeralign="center" align="right">开卡日期</div>
                            <div field="FBirthday" name="FBirthday" width="100" headeralign="center" align="right">生日</div>
                        </div>
                    </div>
                </div>
        </div>        
    </div>
</form>
<script type="text/javascript">
    var comSexType = [{ "id": "-1", "text": "全部" }, { "id": "0", "text": "男" },
                       { "id": "1", "text": "女" }]

    mini.parse();
    var memberLevel = mini.get("memberLevel");
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("grid2");
    //memberLevel.setAjaxOptions({
    //    data: {
    //        FSystemAppID: parent.window.getSystemAppID()
    //    }
    //});
    memberLevel.setUrl("/Member/GetMemberLevel?FSystemAppID=" + parent.window.getSystemAppID());

    function adds() {
        var items = grid.getSelecteds();
        grid.removeRows(items);
        //grid2.addRows(items);
        for (var i = 0, l = items.length; i < l; i++) {
            var rw = items[i];
            var hFItemID = rw.FItemID;
            var mFItemID = "";            
            for (var j = 0, m = grid2.getData().length; j < m; j++) {
                var rs = grid2.getRow(j);
                if (hFItemID == rs.FItemID) {
                    mFItemID = rs.FItemID;
                }
            }
            if (mFItemID == "") {
                grid2.addRow(rw, grid2.getData().length);                
            }
        }
    }

    function removeAll() {
        var items = grid2.getData();
        grid2.removeRows(items);
    }

    function removes() {
        var items = grid2.getSelecteds();
        grid2.removeRows(items);
    }

    function clearloca() {
        mini.get('FCorpItemID').setValue('');
        mini.get('FCorpItemID').setText('');
        mini.get('FCorpName').setValue('');
        mini.get('memberLevel').setValue();
        mini.get('FNumber').setValue('');
    }

    function LoadData() {
        var nowDate = new Date(); //当前日期
        var cDate1 = nowDate.getFullYear() +"-" + mini.getbyName("FDate1").getFormValue();
        var cDate2 = nowDate.getFullYear() + "-" + mini.getbyName("FDate2").getFormValue();
        var membertag = mini.getbyName("TagComBox").getSelecteds();
        var tagList = "";
        for (var i = 0; i < membertag.length; i++) {
            if (tagList != "")
                tagList += ","
            tagList += membertag[i].FItemID;
        }

        var json = "[{";
        json = json + '"mSystemAppID":' + '"' + parent.window.getSystemAppID() + '",';
        json = json + '"mHCorpID":' + '"' + mini.get('FCorpItemID').getValue() + '",';
        json = json + '"mClassID":' + '"' + mini.get('memberLevel').getValue() + '",';
        json = json + '"mDate1":' + '"' + cDate1 + '",';
        json = json + '"mDate2":' + '"' + cDate2 + '",';
        json = json + '"mDays":' + '"' + mini.get('FDays').getValue() + '",';
        json = json + '"FBrDateFlag":' + '"' + (mini.getbyName("FBrDate").checked == true?1:0) + '",';
        json = json + '"mNumber":' + '"' + mini.get('FNumber').getValue() + '",';
        json = json + '"mSex":' + '"' + mini.get('FSex').getValue() + '",';
        json = json + '"mFTags":' + '"' + tagList + '"';
        json = json + "}]";
        grid.load({ mydata: json });
    }

    function FormShown() {
    }

    $(function () {
        LoadData();
        MemberTagLoad();
    });

    function Send() {
        var row = grid2.getData();
        if (row.length > 0) {
            mini.open({
                url: "/Member/SendPreMarIndex",
                title: "会员推送", width: 600, height: 450,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new", row: row};
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    //grid.reload();
                }
            });
        }
        else {
            alert("至少要选择一条数据!");
        }
    }

    function AutoSend() {
        parent.window.showTabById("AutoMarketingList", "自动营销", "../Member/AutoMarketingList");
    }

    function MemberTagLoad() {
        var comBox = mini.get("TagComBox");
        comBox.load("MemberTagList?mSystemAppID=" + parent.window.getSystemAppID());
    }

    function onDrawSummaryCell(e) {
        var result = e.result;
        var grid = e.sender;
        var rows = e.data;

        if (e.field == "FPhone") {
            e.cellHtml = "共" + rows.length + "条记录";
        }
    }

</script>
